package com.superwein.alibaba.dubbo.consumer.controller;

import com.superwein.alibaba.dubbo.api.entity.User;
import com.superwein.alibaba.dubbo.api.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Reference(version = "1.0.0", check = false)
    private UserService userService;

    @GetMapping("/user/{id}")
    public User test(@PathVariable("id") Long id) {
        User user = userService.selectUserById(id);
        redisTemplate.opsForValue().set("user-" + id, user);
        return user;
    }

}
